#!/usr/bin/python3

def findLessThen(s, target):
	start = 0
	end = len(s) - 1

	mid = (start + end) // 2

	while start < end:
		mid_num = s[mid]

		if mid_num < target:
			start = mid + 1
		elif mid_num > target:
			end = mid
		else:
			# 等于视为小于
			end = mid

		mid = (start + end) // 2


	if start == end:
		if target <= s[end]:
			return end
		else:
			return -1
	else:
		return -1


ans = findLessThen([1, 2, 3, 9, 7, 8], 4)
print(ans)

ans = findLessThen([1, 2, 3, 9, 7, 8], 15)
print(ans)

ans = findLessThen([1, 2, 3, 9, 7, 8], 2)
print(ans)

ans = findLessThen([1, 2], 2)
print(ans)

ans = findLessThen([1, 1, 3], 2)
print(ans)

ans = findLessThen([1,  1, 2], 2)
print(ans)

ans = findLessThen([1, 2, 3, 9, 7, 8], 2)
print(ans)
